using System.Collections.Generic;
using Engine;
using Engine.Graphics;

namespace RuthlessConquest {
    public class VisualRoute : Entity {
        public DynamicArray<Planet> Planets = new();

        public Color Color;

        public float Duration = 4f;

        public float SegmentDelay = 0.1f;

        public float TimeToLive { get; set; }

        public VisualRoute(IEnumerable<Planet> planets, Color color) {
            Planets = planets.ToDynamicArray();
            Color = color;
            TimeToLive = Duration + SegmentDelay * (Planets.Count - 2);
        }

        public void Draw(Color colorTransform) {
            FlatBatch2D batch = CameraModule.PrimitivesRenderer.FlatBatch(2);
            for (int i = 0; i < Planets.Count - 1; i++) {
                float num = TimeToLive + SegmentDelay * (i - (Planets.Count - 2));
                float num2 = 0.3f * MathUtils.Sigmoid(MathUtils.Saturate(0.3f * num), 4f) * MathUtils.Saturate(8f * (Duration - num));
                Color ci = Color * colorTransform * num2;
                ci.A = 0;
                Vector2 vector = new(Planets[i].Position);
                Vector2 vector2 = new(Planets[i + 1].Position);
                Vector2.Perpendicular(Vector2.Normalize(vector2 - vector));
                DrawingUtils.QueueThickLine(
                    batch,
                    vector,
                    vector2,
                    220f,
                    240f,
                    0f,
                    20f,
                    ci,
                    Color.Transparent
                );
            }
            TimeToLive -= Time.FrameDuration;
        }
    }
}